/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controlstudent.datos;

import com.controlstudent.entidades.Alumno;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Neil
 */
public class AlumnoDAO {

    private static AlumnoDAO instance = null;

    private AlumnoDAO() {
    }

    public static AlumnoDAO getInstance() {
        if (instance == null) {
            instance = new AlumnoDAO();
        }
        return instance;
    }

    public ArrayList<Alumno> alumnosxapoderado(int id_apod) {
        ArrayList<Alumno> alumnos = null;
        Connection cn = null;

        String sql = "select a.alum_id, a.alum_nom, a.alum_ape from alumno_apoderado aa inner join alumno a\n"
                + "on aa.alumno_id = a.alum_id where aa.apoderado_id=?";

        try {
            alumnos=new ArrayList<>();
            cn = ConnectionManager.getConnection();
            PreparedStatement ps = cn.prepareStatement(sql);
            ps.setInt(1, id_apod);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Alumno a = new Alumno();
                a.setAlum_id(rs.getInt(("alum_id")));
                a.setAlum_nom(rs.getString("alum_nom"));
                a.setAlum_ape(rs.getString("alum_ape"));
                alumnos.add(a);
            }
        } catch (Exception e) {
        } finally {
            try {
                cn.close();
            } catch (SQLException ex) {
            }
        }
        return alumnos;
    }
}
